<!--
  This file is a part of the open-eBackup project.
  This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
  If a copy of the MPL was not distributed with this file, You can obtain one at
  http://mozilla.org/MPL/2.0/.
  
  Copyright (c) [2024] Huawei Technologies Co.,Ltd.
  
  THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
  EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
  MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
  -->

<lv-form [formGroup]="formGroup" [lvLabelColon]="false" class="formGroup">
  <!-- 用户类型 -->
  <lv-form-item *ngIf="isOceanProtect || isCyberengine">
    <lv-form-label lvRequired>
      {{'common_user_type_label' | i18n}}
    </lv-form-label>
    <lv-form-control>
      <lv-select formControlName="userType" [lvOptions]="userTypeOptions" lvValueKey="value">
      </lv-select>
    </lv-form-control>
  </lv-form-item>
  <lv-form-item>
    <lv-form-label lvRequired>
      {{ 'common_name_label' | i18n }}
    </lv-form-label>
    <lv-form-control [lvErrorTip]="userNameErrorTip">
      <input [lv-tooltip]="nameToolTips" lvTooltipTrigger="focus" lvTooltipPosition="topLeft" lvTooltipTheme="light"
        lv-input type="text" formControlName="userName" autocomplete="new-password" />
    </lv-form-control>
  </lv-form-item>
  <ng-container *ngIf="formGroup.value.userType === dataMap.loginUserType.local.value">
    <!-- 登录方式 -->
    <lv-form-item *ngIf="isOceanProtect">
      <lv-form-label>
        {{'common_login_method_label' | i18n}}
        <i lv-icon="aui-icon-help" lv-tooltip="{{'system_login_method_help_label' | i18n}}" lvTooltipTheme="light"
          class="configform-constraint" lvColorState='true'></i>
      </lv-form-label>
      <lv-form-control>
        <lv-select formControlName="loginType" [lvOptions]="methodTypeOptions" lvValueKey="value">
        </lv-select>
        <ng-container *ngIf="isOceanProtect && formGroup.value.loginType === dataMap.loginMethod.email.value">
          <p class="aui-text-help-sm" [innerHTML]="dynamicCodeHelp"></p>
        </ng-container>
      </lv-form-control>
    </lv-form-item>
    <lv-form-item>
      <lv-form-label lvRequired>
        {{ 'common_password_label' | i18n }}
      </lv-form-label>
      <lv-form-control [lvErrorTip]="baseUtilService.pwdErrorTip">
        <aui-inupt-with-eye [lv-tooltip]="pwdComplexTipTpl" lvTooltipTrigger="focus" lvTooltipPosition="topLeft"
          lvTooltipTheme="light" formControlName="userPassword" [lvPasteAllowed]="false"></aui-inupt-with-eye>
      </lv-form-control>
    </lv-form-item>
    <lv-form-item>
      <lv-form-label lvRequired>{{ 'common_confirmpwd_label' | i18n }}</lv-form-label>
      <lv-form-control [lvErrorTip]="baseUtilService.pwdErrorTip">
        <aui-inupt-with-eye formControlName="confirmPassword" [lvPasteAllowed]="false"></aui-inupt-with-eye>
      </lv-form-control>
    </lv-form-item>
    <!-- 收件人邮箱地址 -->
    <ng-container *ngIf="isOceanProtect && formGroup.value.loginType === dataMap.loginMethod.email.value">
      <lv-form-item>
        <lv-form-label lvRequired>{{ 'system_recipient_email_address_label' | i18n }}
          <i lv-icon="aui-icon-help" lv-tooltip="{{'system_email_address_placeholder_label' | i18n}}"
            lvTooltipTheme="light" class="configform-constraint" lvColorState="true"></i>
        </lv-form-label>
        <lv-form-control [lvErrorTip]="emailErrorTip">
          <input lv-input formControlName="dynamicCodeEmail" />
        </lv-form-control>
      </lv-form-item>
    </ng-container>
  </ng-container>
  <lv-form-item>
    <lv-form-label lvRequired>{{ 'common_role_label' | i18n }}</lv-form-label>
    <lv-form-control [lvErrorTip]="baseUtilService.requiredErrorTip">
      <lv-select [lvOptions]="roleOptions" formControlName="roleId" lvValueKey="roleId"></lv-select>
    </lv-form-control>
  </lv-form-item>
  <lv-form-item>
    <lv-form-label>{{ 'common_desc_label' | i18n }}</lv-form-label>
    <lv-form-control [lvErrorTip]="baseUtilService.lengthErrorTip">
      <lv-input-lint class="user-desc">
        <textarea rows="3" maxlength="255" formControlName="description" lv-input style="resize: vertical;"
          [lvAutosize]="{ minRows: 4, maxRows: 8 }"></textarea>
      </lv-input-lint>
    </lv-form-control>
  </lv-form-item>
  <ng-container *ngIf="formGroup.value.roleId !== 6">
    <lv-form-item>
      <lv-form-label>
        {{ 'system_user_maxconnections_label' | i18n }}
        <i lv-icon="aui-icon-help" lvTooltipTheme="light" lvTooltipPosition="bottom"
          lv-tooltip="{{ 'system_maxconnection_tip_label' | i18n }}" class="configform-constraint"
          lvColorState='true'></i>
      </lv-form-label>
      <lv-form-control>
        <lv-group>
          <lv-form-control>
            <lv-switch formControlName="sessionControl" (ngModelChange)="sessionControlChange($event)"></lv-switch>
          </lv-form-control>
        </lv-group>
        <div></div>
        <lv-group>
          <lv-form-control *ngIf="formGroup.get('sessionControl').value" [lvErrorTip]="sessionErrorTip">
            <input lv-input type="text" (blur)="sessionLimitBlur()" formControlName="sessionLimit" placeholder="1~8" />
          </lv-form-control>
        </lv-group>
      </lv-form-control>
    </lv-form-item>
  </ng-container>
  <ng-container *ngIf="formGroup.value.roleId === 7">
    <lv-form-item>
      <lv-form-label>{{ 'system_password_no_time_limit_label' | i18n }}
      </lv-form-label>
      <lv-form-control>
        <lv-switch formControlName="neverExpire"></lv-switch>
        <div class="block-tips" *ngIf="formGroup?.value.neverExpire">
          <i lv-icon="lv-icon-status-warning-info" lvColorState="true" class="type-icon icon-tips"></i>
          <span class="form-tips">
            {{ 'system_password_no_time_limit_tips_label' | i18n }}
          </span>
        </div>
      </lv-form-control>
    </lv-form-item>
  </ng-container>
</lv-form>

<ng-template #pwdComplexTipTpl>
  <span [innerHTML]="pwdComplexTipLabel"></span>
</ng-template>